package Final;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.border.TitledBorder;

public class SeasonEntry2 {

    public static void main(String[] args) {

        Runnable r = new Runnable() {

            public void run() {
            	
            	JLabel ClassCodeL = new JLabel("Class Code");
            	JTextField ClassCodeT = new JTextField("Class Code");
            	JLabel ClassDescriptionL = new JLabel("Class Description");
            	JTextField ClassDescriptionT = new JTextField("Class Description");
            	
            	JLabel SeasonCodeL = new JLabel("Season Code");
            	JTextField SeasonCodeT = new JTextField("Season");
            	JLabel SeasonDescriptionL = new JLabel("Season Description");
            	JTextField SeasonDescriptionT = new JTextField("Season Description");

            	JButton searchb = new JButton("Search");
            	JLabel newseasonl = new JLabel("Season Code:");
            	JTextField newseasont = new JTextField();
            	JButton AddB = new JButton("Add");
            	JButton Close = new JButton("Close");	
            	
        		SeasonCodeL.setBounds(185,105,85,20);		
        		SeasonCodeL.setFont(new Font("arial", Font.PLAIN, 11));
        		SeasonCodeT.setBounds(185,125,65,20);
        		SeasonCodeT.setDocument(new JTextFieldLimit(4));
        		SeasonDescriptionL.setBounds(285, 105, 95, 20);
        		SeasonDescriptionL.setFont(new Font("arial", Font.PLAIN,11));
        		SeasonDescriptionT.setBounds(285,125,95,20);
        		SeasonDescriptionT.setDocument(new JTextFieldLimit(11));
        		
            	ClassCodeL.setBounds(25,105,180,20);
        		ClassCodeL.setFont(new Font("arial", Font.PLAIN, 11));
        		ClassCodeT.setBounds(25,125,55,20);
        		ClassCodeT.setDocument(new JTextFieldLimit(2));
        		ClassDescriptionL.setBounds(85,105,150,20);
        		ClassDescriptionL.setFont(new Font("arial", Font.PLAIN, 11));
        		ClassDescriptionT.setBounds(85,125,85,20);
        		ClassDescriptionT.setDocument(new JTextFieldLimit(11));
        		
                final JFrame frame = new JFrame("Season Entry");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                final JPanel panel = new JPanel(new BorderLayout(5,5));
                panel.setBorder( new TitledBorder("Season Entry Form") );


                JPanel Searchpanel = new JPanel();
                Searchpanel.setLayout(null);
                //Searchcomponent.setBorder(new TitledBorder("Search Component") );
                Searchpanel.setPreferredSize(new Dimension(100,100));

                //JPanel Searchcomponent = new JPanel(new FlowLayout(FlowLayout.LEFT, 50,50));
                JPanel NullPanel = new JPanel();
                NullPanel.setLayout(null);
                NullPanel.setPreferredSize(new Dimension (200,100));
                //Searchcomponent.setBorder(new TitledBorder("Search Component") );

                SeasonCodeL.setLocation(0, 0);
                SeasonCodeT.setLocation(0, 20);
                
                SeasonDescriptionL.setLocation(75, 0);
                SeasonDescriptionT.setLocation(75,20);


                ClassCodeL.setLocation(175, 0);
                ClassCodeT.setLocation(175,20);
                
                ClassDescriptionL.setLocation(235,0);
                ClassDescriptionT.setLocation(235, 20);
                
                searchb.setBounds(40, 40, 80, 20);
                searchb.setLocation(0,80);
                
                Searchpanel.add(SeasonCodeL);
                Searchpanel.add(SeasonCodeT);
                Searchpanel.add(SeasonDescriptionL);
                Searchpanel.add(SeasonDescriptionT);
                Searchpanel.add(ClassDescriptionL);
                Searchpanel.add(ClassDescriptionT);
                Searchpanel.add(ClassCodeL);
                Searchpanel.add(ClassCodeT);
                Searchpanel.add(searchb);
               
                Searchpanel.add(newseasonl);
                Searchpanel.add(newseasont);

                NullPanel.add(ClassDescriptionL);
                NullPanel.add(ClassCodeT);
                NullPanel.add(ClassCodeL);
                NullPanel.add(ClassDescriptionT);
                NullPanel.add(SeasonCodeL);
                NullPanel.add(SeasonCodeT);
                NullPanel.add(SeasonDescriptionL);
                NullPanel.add(SeasonDescriptionT);
                NullPanel.add(newseasonl);
                NullPanel.add(newseasont);


                
                
                /* change the look of the layout
                final UIManager.LookAndFeelInfo[] plafInfos = UIManager.getInstalledLookAndFeels();
                String[] plafNames = new String[plafInfos.length];
                for (int ii=0; ii<plafInfos.length; ii++) {
                    plafNames[ii] = plafInfos[ii].getName();
                }
                final JComboBox plafChooser = new JComboBox(plafNames);
                Searchcomponent.add(plafChooser);

                final JCheckBox pack = new JCheckBox("Pack on PLAF change", true);
                Searchcomponent.add(pack);

                plafChooser.addActionListener( new ActionListener(){
                    public void actionPerformed(ActionEvent ae) {
                        int index = plafChooser.getSelectedIndex();
                        try {
                            UIManager.setLookAndFeel(
                                plafInfos[index].getClassName() );
                            SwingUtilities.updateComponentTreeUI(frame);
                            if (pack.isSelected()) {
                                frame.pack();
                                frame.setMinimumSize(frame.getSize());
                            }
                        } catch(Exception e) {
                            e.printStackTrace();
                        }
                    }
                } );
*/
                panel.add(Searchpanel, BorderLayout.NORTH);

                panel.add(NullPanel, BorderLayout.NORTH);
/*
                JPanel dynamicLabels = new JPanel(new BorderLayout(4,4));
                dynamicLabels.setBorder(new TitledBorder("BorderLayout(4,4)") );
                panel.add(dynamicLabels, BorderLayout.WEST);

                final JPanel labels = new JPanel(new GridLayout(0,2,3,3));
                labels.setBorder(
                    new TitledBorder("GridLayout(0,2,3,3)") );

                JButton addNew = new JButton("Add Another Label");
                dynamicLabels.add( addNew, BorderLayout.NORTH );
                addNew.addActionListener( new ActionListener(){

                    private int labelCount = 0;

                    public void actionPerformed(ActionEvent ae) {
                        labels.add( new JLabel("Label " + ++labelCount) );
                        frame.validate();
                    }
                } );

                dynamicLabels.add( new JScrollPane(labels), BorderLayout.CENTER );
*/                
                String[] header = {"Name", "Value"};
                String[] a = new String[0];
                String[] names = System.getProperties().
                    stringPropertyNames().toArray(a);
                String[][] data = new String[names.length][2];
                for (int ii=0; ii<names.length; ii++) {
                    data[ii][0] = names[ii];
                    data[ii][1] = System.getProperty(names[ii]);
                }
                DefaultTableModel model = new DefaultTableModel(data, header);
                JTable table = new JTable(model);
                try {
                    // 1.6+
                    table.setAutoCreateRowSorter(true);
                } catch(Exception continuewithNoSort) {
                }
                JScrollPane tableScroll = new JScrollPane(table);
                Dimension tablePreferred = tableScroll.getPreferredSize();
                tableScroll.setPreferredSize(
                    new Dimension(tablePreferred.width, tablePreferred.height/3) );

                JPanel imagePanel = new JPanel(new GridBagLayout());
                imagePanel.setBorder(new TitledBorder("GridBagLayout()") );

                BufferedImage bi = new BufferedImage(200,200,BufferedImage.TYPE_INT_ARGB);
                Graphics2D g = bi.createGraphics();
                GradientPaint gp = new GradientPaint(
                    20f,20f,Color.red, 180f,180f,Color.yellow);
                g.setPaint(gp);
                g.fillRect(0,0,200,200);
                ImageIcon ii = new ImageIcon(bi);
                JLabel imageLabel = new JLabel(ii);
                imagePanel.add( imageLabel, null );

                JSplitPane splitPane = new JSplitPane(
                    JSplitPane.VERTICAL_SPLIT,
                    tableScroll,
                    new JScrollPane(imagePanel));
                panel.add( splitPane, BorderLayout.CENTER );

                frame.setContentPane(panel);

                frame.pack();

                frame.setLocationRelativeTo(null);
                try {
                    // 1.6+
                    frame.setLocationByPlatform(false);// set location
                    frame.setMinimumSize(frame.getSize());
                } catch(Throwable ignoreAndContinue) {
                }

                frame.setVisible(true);
            }
        };
        SwingUtilities.invokeLater(r);
    }
}